package com.datastructures2.字符串;

/**
 * @author MaoLin Wang
 * @date 2020/10/5 10:03 上午
 */
public class 验证回文 {
    public static boolean isHuiWen(String str){
        if (str==null || "".equals(str)){
            return false;
        }
        int left=0;
        int right=str.length()-1 ;
        char[] chars = str.toCharArray();
        while (left<right){
            if (!Character.isLetterOrDigit(chars[left])){
                left++;
            }
           else if (!Character.isLetterOrDigit(chars[right])){
                right--;
            }
          else  if (Character.toLowerCase(chars[left])==Character.toLowerCase(chars[right])){
                left++;
                right--;
            }else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(isHuiWen("A man, a plan, a canal: Panama"));
    }
}
